package org.lanqiao.webfm.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import javacommon.base.BaseServletAdapter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.webfm.model.Type;
import org.lanqiao.webfm.service.TypeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Servlet implementation class IndexServlet
 */
@WebServlet("/Index.do")
public class IndexServlet extends BaseServletAdapter {
	private static final long serialVersionUID = 1L;
	private static final Logger LOGGER = LoggerFactory.getLogger(IndexServlet.class);
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//得到商品的分类信息并共享
		try {
			Map<Type, List<Type>> typeInfos = typeService.findTypeInfo();
			request.setAttribute("typeInfos", typeInfos);
			request.getRequestDispatcher("/indexf.jsp").forward(request, response);
		} catch (SQLException e) {
			LOGGER.error(e.getMessage(), e);
			throw new RuntimeException(e);
		}
		//转发
	}
	private TypeService typeService = TypeService.getInstance();
}
